<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Alejandro Casas
 * Date: 1/28/13
 * Time: 3:49 PM
 * To change this template use File | Settings | File Templates.
 */
require_once 'DataLoader.php';

include_once('httpful-0.2.0.phar');
class PlayerWS
{
    private $client;
    public function __construct() {
        $this->client = $_SESSION['player_server_url'];
    }

    public function RegisterPlayer($name,$birthday,$mail,$gender,$pass,$country,$city,$sports)
    {
        $slist=explode(",",$sports);
        $jsonsports='';
        foreach($slist as $s)
        {
            $jsonsports=$jsonsports.'{"name":"'.$s.'"},';
        }
        $jsonsports = substr($jsonsports, 0, -1);
        $uri=$this->client."RegisterPlayer";
        $parameters='{
    "name":"'.$name.'",
	"birthday":"'.$birthday.'",
	"mail":"'.$mail.'",
	"gender":"'.$gender.'",
	 "pass":"'.$pass.'",
	"country":"'.$country.'",
	 "city":"'.$city.'",
	"sports":['.$jsonsports.']
	 }';
        $r = \Httpful\Request::post($uri)
            ->sendsJson()
            ->body($parameters)
            ->send();
        return $r;
    }

    public function SendEventParticipationRequest ($mail,$eventId)
    {
        $uri=$this->client."SendEventParticipationRequest/".$mail."/".$eventId;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function SendEventSuggestion($mailSender,$mailTo,$eventId)
	{
        $uri=$this->client."SendEventSuggestion/".$mailSender."/".$mailTo."/".$eventId;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function SendCoachingRequest($mailFrom,$mailTo)
	{
        $uri=$this->client."SendCoachingRequest/".$mailFrom."/".$mailTo;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function SendFriendRequest($mailFrom,$mailTo)
	{
        $uri=$this->client."SendFriendRequest/".$mailFrom."/".$mailTo;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }


	public function Accept_friend_request($mailFrom,$mailTo)
	{
        $uri=$this->client."Accept_friend_request/".$mailFrom."/".$mailTo;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }


	public function Reject_friend_request($mailFrom,$mailTo)
	{
        $uri=$this->client."Reject_friend_request/".$mailFrom."/".$mailTo;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function GetFriendRequests($mail)
	{
        $uri=$this->client."GetFriendRequests/".$mail;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }


	public function SetPlayerAvailable($mail,$startDate,$endDate,$privacy,$sports)
	{
        $uri=$this->client."SetPlayerAvailable/".$mail."/".$startDate."/".$endDate."/".$privacy."/".$sports;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function SetPlayerUnavailable($mail)
	{
        $uri=$this->client."SetPlayerUnavailable/".$mail;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function EditPlayerProfile($mail,$description,$country,$picture,$phone,$carrier,$city)
	{
        $uri=$this->client."EditPlayerProfil/".$mail."/".$description."/".$country."/".$picture."/".$phone."/".$carrier."/".$city;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function GetPlayerInstructors($mail)
	{
        $uri=$this->client."GetPlayerInstructors/".$mail;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }

	public function GetEventSuggestions($mail)
	{
        $uri=$this->client."GetEventSuggestions/".$mail;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;
    }
}
